package com.example;

/**
 * @desc:
 * @author: Shoko
 * @date: 2025/6/6
 */
import java.util.HashMap;
import java.util.Map;

public class AddressBook {
    private Map<String, String> contacts = new HashMap<>();

    public void addContact(String name, String phone) {
        contacts.put(name, phone);
        System.out.println("联系人 " + name + " 添加成功");
    }

    public void deleteContact(String name) {
        if (contacts.containsKey(name)) {
            contacts.remove(name);
            System.out.println("联系人 " + name + " 删除成功");
        } else {
            System.out.println("联系人 " + name + " 不存在");
        }
    }

    public String viewContact(String name) {
        if (contacts.containsKey(name)) {
            String phone = contacts.get(name);
            System.out.println("联系人: " + name + ", 电话号码: " + phone);
            return phone;
        } else {
            System.out.println("联系人 " + name + " 不存在");
            return null;
        }
    }
}
